<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<?php
$this->addCssFile('/project/apps/ecga/styles/style.css');
$this->addCssFile('/project/apps/ecga/styles/layout.css');
$this->addCssFile('/project/apps/ecga/styles/menu.css');
$this->addScriptFile('/statics/js/mootools/core.js');
$this->addScriptFile('/statics/js/storage/storage.js');

$this->addCssFile('/project/apps/ecga/styles/form.css');
$this->addCssFile('/statics/js/facebox/css/facebox.css');
$this->addScriptFile('/statics/js/facebox/facebox.js');
?>
<body>
<style type="text/css">
#setmenusbox .container { _width:600px; }
#setmenusbox ul { list-style:none; display:block; }
#setmenusbox ul li { float:left; margin-left: 3px; }
#setmenusbox .content {overflow: hidden; height:25px; width: auto; _width: 100px; }
#setmenusbox .wrap { width: 400px; overflow: hidden; _width: 500px; }

#setmenusbox .desc { width: 65px; overflow: hidden; }
#setmenusbox .bottom {float: right; width: 150px; }
.loading { padding:5px; position:absolute; left:1px; right:1px; }
</style>
<div class="loading">加载中...</div>
<div class="top" style="visibility:hidden;">
	<?php if ($projectBool) : ?>
	<h1><img src="<?php $this->imageByPath('/project/apps/ecga/images/logitech_logo.gif') ?>" width="104" height="45" /></h1>
    <?php else :?>
	<h1><img src="<?php $this->imageByPath('/project/apps/ecga/images/top_logo.gif') ?>" width="104" height="45" /></h1>
    <?php endif;?>
	<ul>
		<?php if ($projectBool) :?>
		<li><?php $this->put($user->userName); ?>，欢迎您使用罗技线上价格跟踪平台！</li>
		<?php else :?>
        <li><?php $this->put($user->userName); ?>，欢迎您使用ECGA数据挖掘平台！</li>
        <?php endif;?>
		<!--<li><a href="/" target="_blank">我的网店</a></li>-->
        <li>|</li>
        <li> <a href="#" rel="facebox" title="修改密码" id="modifyPwdLink">修改密码</a></li>
        <li>|</li>
        <li><a href="profile.php?a=logout">退出登录</a></li>
  </ul>
</div>

<div class="nav-bar" style="visibility:hidden;">
    <ul>
      <li class="controlcenter"><a href="index.php?a=welcome" target="mainFrame">控制中心</a></li>
      <li class="new-page-button"><a href="javascript:;">&nbsp;</a></li>
    </ul>
    <ul class="label-container nav">
    </ul>
    <ul class="subnav" style="display:none;">
        <li><a href="#" id="clearCache">清除缓存</a></li>
        <li class="config"><a href="#" title="配置常用菜单" rel="facebox" id="setmenus">配置常用菜单</a></li>
        <li class="help"><a href="#">帮助</a></li>
    </ul>
</div>

<div class="wrapper" style="visibility:hidden;">
    <div class="left">
        <ul class="menuset">
            <?php foreach ($menus as $group): ?>
            <li class="menu-item">
                <h3><div><?php $this->put(l($group['name'])); ?></div></h3>
                <ul>
                    <?php foreach ($group['items'] as $item): ?>
                    <li><?php $this->txtLink(l($item['name']), $item['controller'] . '.php?a=' . $item['act']); ?></li>
                    <?php endforeach; ?>
                </ul>
            </li>
            <?php endforeach; ?>
        </ul>
        <div class="favorite-menu" style="display:none;">
            <h3 style="cursor:pointer">常用菜单</h3>
            <ul>
                <?php foreach ($commonMenus as $item): ?>
                <li><?php $this->txtLink(l($item['name']), $item['controller'] . '.php?a=' . $item['act']); ?></li>
                <?php endforeach; ?>
           </ul>
        </div>
    </div>
    <div class="center">
    </div>
    <div class="right" >
        <div id="pageContainer" style="width:100%">
        </div>
    </div>
</div>
<script type="text/javascript">
    var navItemHeight = 0;
    var myAccordion = null;
    function init() {
        setSize();
        $$(".loading").hide();
        $$(".top, .nav-bar, .wrapper").setStyle("visibility", "visible");
        myAccordion = new Fx.Accordion($$('.menu-item h3'), $$('.menu-item ul'), {
            display: 0,
            fixedHeight: navItemHeight,
            alwaysHide: false
        }).addEvent("active", function(t, el){
            $$(".menuset .selected").removeClass("selected");
            var li = t.getParent("li");
            li.addClass.delay(500, li, ["selected"]);
            el.setStyle.delay(500, el, 'overflow-y', 'auto');
        }).addEvent("background", function(t, el) {
            el.setStyle('overflow-y', 'hidden');
        });
        $$(".menu-item")[0].addClass("selected");
    }

    function setSize() {
        var docSize = document.getSize();
        var top = document.getElement(".top");
        var nav = document.getElement(".nav-bar");
        var wrapper = document.getElement(".wrapper");
        var left = document.getElement(".wrapper .left");
        var docHeight = docSize.y;
        var wrapperHeight = docHeight - top.getSize().y - nav.getSize().y

        wrapper.getElements(".left, .center, .right, iframe").forEach(function(el) {
            el.setStyle("height", wrapperHeight);
        });

        navItemHeight = wrapperHeight;
        var favoriteMenuHeight = document.getElement(".favorite-menu").getSize().y;

        navItemHeight -= parseInt(favoriteMenuHeight);
        $$(".menu-item h3").getStyle("height").forEach(function(val){
            navItemHeight -= parseInt(val);
        });
    }

    window.addEvent("domready", function() {
        if (Storage.read("favoriteMenuMix")) {
            $$(".favorite-menu").addClass("favorite-menu-mix");
        }

        var wrapper = $$(".wrapper")[0];
        var left = wrapper.getElement(".left");
        var center = wrapper.getElement(".center");
        var right = wrapper.getElement(".right");
        var rightOrgMarginLeft = right.getStyle("marginLeft");
        center.addEvent("click", function() {
            var leftDisplayed = left.isDisplayed();
            if (leftDisplayed) {
                center.addClass("closed");
                right.setStyle("marginLeft", center.offsetWidth);
                left.hide();
            } else {
                center.removeClass("closed");
                right.setStyle("marginLeft", rightOrgMarginLeft);
                left.show();
            }

            setSize();
        });

        init();

        window.addEvent("resize", function() {
            setSize();
            myAccordion.effects.fixedHeight = navItemHeight;
            myAccordion.elements.forEach(function(el){
                myAccordion.options.fixedHeight = navItemHeight;
                el.fullHeight = navItemHeight;
            });
            $$(".menuset .selected ul").setStyle("height", navItemHeight);

            $$("#pageContainer iframe").setStyle('width', document.body.getElement('.right').offsetWidth);
        });

        $$(".favorite-menu h3").addEvent("click", function() {
            var fm = $$(".favorite-menu")[0];
            fm.toggleClass("favorite-menu-mix");
            if (fm.hasClass("favorite-menu-mix")) {
                Storage.write("favoriteMenuMix", 1);
            } else {
                Storage.remove("favoriteMenuMix");
            }
            window.fireEvent("resize");
        });

        var cp = window.controlPanel = new ControlPanel();

        $$(".favorite-menu a").addEvent("click", openInCurrentPage.create({bind: true}));
        $$(".controlcenter a").addEvent("click", openInCurrentPage.create({bind: true}));

        function openInCurrentPage(event) {
            event.stop();
            self = event.target;
            cp.currentPage.setUrl(self.get("href"));
        }

        window.fb = new Facebox({showFooter: false, "width": "auto"});

        /*防止页面还没加载完时一点击链接跳转到丑陋的页面*/
        $('modifyPwdLink').href= '/profile.php?a=modifyPassword';
        $('setmenus').href= '/admin/index.php?a=setStockMenus';
    });

(function () {
    this.ControlPanel = new Class({
        pages: [],
        defaultPageUrl: "<?php $this->put($defaultMenu);?>.php",
        initialize: function() {
            $$(".new-page-button").addEvent("click", function(){
                var page = this.addNewPage("about:blank");
                page.selected();
            }.bind(this));

            this.labelContainer = document.getElement(".label-container");
            var self = this;
            $$(".menu-item ul li a").each(function(el){
                el.addEvent("click", function(e){
                    self.openPage(this.get("href"));
                    e.stop();
                }.bindWithEvent(el))
            });
            var data = Storage.read("controlPanelStatus");
            if (data && data.sessId == Cookie.read("YEGOL_Shop")) {
                var currentPage = data.currentPage;
                data.pages.each(function(p) {
                    this.addNewPage(p.u).setTitle(p.t);
                }, this);
                if (!this.pages[currentPage]) currentPage = this.pages.length - 1;
                this.pages[currentPage].selected();
            } else {
                var page = this.addNewPage(this.defaultPageUrl);
                page.setTitle("欢迎页");
                page.selected();
            }
        },
        addNewPage: function(url) {
            if (this.pages.length >= 5) {
                //this.pages.getLast().setUrl(url);
                alert("对不起，控制面板最多允许同时打开5个页面，您可以将不使用的页面关闭！");
                return;
            }
            var page = new Page(url, this);
            return page;
        },
        openPage: function(url) {
            if (this.pages.length == 0) this.addNewPage();
            this.currentPage.setUrl(url);
        },
        store: function() {
            var data = {
                pages: [],
                currentPage: 0,
                sessId: Cookie.read("YEGOL_Shop")
            };
            this.pages.each(function(p, k) {
                if (!p.url) return;
                data.pages.include({u:p.url, t:p.title});
                if (this.currentPage == p) {
                    data.currentPage = k;
                }
            }, this);
            Storage.write("controlPanelStatus", data);
        }
    });

    var Page = new Class({
        initialize: function(url, controlPanel) {
            var docSize = document.getSize();
            var top = document.getElement(".top");
            var nav = document.getElement(".nav-bar");
            var docHeight = docSize.y;
            this.wrapperHeight = docHeight - top.getSize().y - nav.getSize().y;
            this.url = url;
            this.controlPanel = controlPanel
            controlPanel.pages.include(this);
            this.createLabel();
            this.createIframe();

            this.setTitle("未命名");
        },
        createLabel: function() {
            this.label = new Element("li", {"class": "nav-item"}).adopt(
                    new Element("a", {"class": "txt", "href": "javascript:void 0;", html: "加载中.."})
                ).inject(this.controlPanel.labelContainer);

            this.label.addEvent("click", this.labelClick.bindWithEvent(this));
            this.addCloseBtns();
        },
        setTitle: function(title) {
            this.title = title;
            this.label.getLast().set("text", title);
        },
        labelClick: function(event) {
            if (event.target.hasClass("icon-close")) {
                this.close();
            } else {
                this.selected();
            }
        },
        addCloseBtns: function() {
            var controlPanel = this.controlPanel;
            if (controlPanel.pages.length > 1) {
                controlPanel.pages.each(function(page) {
                    var el = page.label.getElement("a.icon-close");
                    if (!el) {
                        new Element("a", {
                            "href": "javascript:void 0;",
                            "class": "icon-close",
                            "html": "&nbsp;"}).inject(page.label, "top");
                    }
                });
            } else {
                controlPanel.labelContainer.getElements(".icon-close").dispose();
            }
        },
        createIframe: function() {
            this.iframe = new Element("iframe", {
                height: this.wrapperHeight + "px",
                frameBorder: 0,
                src: "about:blank",
                width: $(document.body).getElement('.right').offsetWidth
            });
            this.iframe.inject($("pageContainer"));
        },
        selected: function() {
            var self = this;
            if (!this.pageSelected) {
                this.loadPage(this.url);
                this.iframe.addEvent("load", function() {
                    if (this.src == "about:blank") return;
                    var title = this.contentWindow.document.title;
                    if (title == "") title = '未命名';
                    self.setTitle(title);
                    self.controlPanel.store();
                });
            }
            this.controlPanel.pages.each(function(page){
                page.label.removeClass("select");
                page.iframe.hide();
            });
            this.pageSelected = true;
            this.label.addClass("select");
            this.iframe.show();
            this.controlPanel.currentPage = this;
            this.controlPanel.store()
        },
        close: function() {
            this.label.dispose();
            this.iframe.dispose();
            this.controlPanel.pages.erase(this);
            this.addCloseBtns();
            this.controlPanel.pages.getLast().selected();
            this.controlPanel.store();
        },
        setUrl: function(url) {
            this.url = url;
            this.loadPage(url);
        },
        loadPage: function(url){

            this.iframe.src = url;
        }
    });
})();
function postInfo() {
    var values = [];
    var menus = $('setmenusbox').getElement('form')['act[]'];
    for(var i = 0; i < menus.length; i++) {
        if (menus[i].checked) {
            values.push( menus[i].value);
        }
    }
    if (values.length > 8) {
        alert('对不起，您只能选择8个常用菜单项！');
        return;
    }
    new Request.JSON({
        type: 'post',
        url: '/admin/index.php?a=saveStockMenus',
        data: 'ids=' + values.join(','),
        onSuccess : function(s) {
            closeFacebox();
			window.location.reload();
        }
    }).post();
}
    /*修改密码时检测函数*/
    function checkInfo(tag) {
        if (tag) {
            if ($('originPassword').value.trim() == '') {
                $('adviceMsg').innerHTML = '请输入原密码';
                $('originPassword').focus();
                return false;
            }

            if ($('newPassword').value.trim() == '') {
                $('adviceMsg').innerHTML = '新密码不能为空';
                $('newPassword').focus();
                return false;
            }

            if ($('newPassword').value.trim().length < 6 || $('repeatNewPassword').value.trim().length < 6) {
                $('adviceMsg').innerHTML = '密码长度至少为6个字符'
                $('newPassword').focus();
                return false;
            }

            if ($('repeatNewPassword').value.trim() == '') {
                $('adviceMsg').innerHTML = '请确认新密码';
                $('repeatNewPassword').focus();
                return false;
            }

            if ($('newPassword').value != $('repeatNewPassword').value) {
                $('adviceMsg').innerHTML = '确认密码与新密码输入不一致';
                $('repeatNewPassword').focus();
                return false;
            }
            var jsonRequest = new Request.JSON({
            url: "profile.php?a=doModifyPassword",
                onComplete: function(res){
                    if (res.result){
                       $('adviceMsg').set('class', 'validation-cmpltn');
                    }
                    $('adviceMsg').innerHTML = res.message;
                }
            }).post($('theForm'));

        } else {
            window.fb.close();
        }

    }
</script>
</body>



</html>
